package com.bkhc.common.config;

import com.bkhc.common.annotation.ApiRestController;
import com.bkhc.common.annotation.WebRestController;
import com.bkhc.common.permissions.filter.SsoFilter;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.HashSet;
import java.util.Set;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Value("${spring.application.name}")
    public String appName;
        /**
         * 请求路径添加统一前缀
         *
         * @param configurer
         */
        @Override
        public void configurePathMatch(PathMatchConfigurer configurer) {
            configurer.addPathPrefix("/", c -> c.isAnnotationPresent(WebRestController.class))
                    .addPathPrefix("/service", c -> c.isAnnotationPresent(ApiRestController.class));
        }

        @Bean
        public FilterRegistrationBean testFilterRegistration() {
            FilterRegistrationBean registration = new FilterRegistrationBean(new SsoFilter());
            registration.addUrlPatterns("/*"); //
            registration.setName("SsoFilter");
            registration.setOrder(1);
            registration.addInitParameter("exclusions", "/service");
            registration.addInitParameter("appName", appName);
            return registration;
        }


}
